using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;

namespace PolicyInjection.AdditionalMatchingRules.Tests
{
    [TestClass]
    public class CompositionalMatchingRulesFixture
    {
        [TestMethod, DeploymentItem("CompositionalMatchingRules.config")]
        public void FindMatches()
        {
            IConfigurationSource configurationSource = new FileConfigurationSource("CompositionalMatchingRules.config");
            PolicySetFactory factory = new PolicySetFactory(configurationSource);
            PolicySet policySet = factory.Create();

            foreach (MethodBase method in typeof(Target).GetMethods())
            {
                List<Policy> ps = new List<Policy>(policySet.GetPoliciesFor(method));
                switch (method.Name)
                {
                    case "BAndCAndDeny":
                        Assert.AreEqual(1, ps.Count);
                        break;
                    case "AAndB":
                        Assert.AreEqual(1, ps.Count);
                        break;
                    default:
                        Assert.AreEqual(0, ps.Count);
                        break;
                }
            }
        }
    }

   

    class Target
    {
        [Tag("A")]
        public void OnlyA()
        {
        }

        [Tag("B")]
        public void OnlyB()
        {
        }

        [Tag("B")]
        [Tag("A")]
        public void AAndB()
        {
        }

        [Tag("B")]
        [Tag("A")]
        [Deny]
        public void AAndBAndDeny()
        {
        }

        [Tag("C")]
        [Tag("A")]
        [Deny]
        public void AAndCAndDeny()
        {
        }
        [Tag("C")]
        [Tag("B")]
        [Deny]
        public void BAndCAndDeny()
        {
        }
    }
    
}
    public class Deny : Attribute
    {
    }
